package org.javaboy.vhr.controller.emp;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.javaboy.vhr.model.Employeeec;
import org.javaboy.vhr.model.RespBean;
import org.javaboy.vhr.model.RespPageBean;
import org.javaboy.vhr.service.EmployeeecService;
import org.javaboy.vhr.service.OpLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: vhr
 * @description:
 * @author: yang
 * @create: 2020-06-30 13:28
 **/
@RestController
@RequestMapping("/employeeec")
public class EmployeeecController {
    @Autowired
    private EmployeeecService employeeecService;

    @Autowired
    OpLogService opLogService;

    @GetMapping("/")
    public RespPageBean getEmployeeByPage(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "10") Integer pageSize) {
        PageHelper.startPage(currentPage, pageSize);
        Page<Employeeec> page = employeeecService.getAll();
        List<Employeeec> result = page.getResult();
        long total = page.getTotal();
        return new RespPageBean(total, result);
    }

    @RequestMapping("/add")
    public RespBean add(@RequestBody Employeeec employeeec){
        boolean flag=employeeecService.add(employeeec);
        if (flag) {
            //获取当前方法并调用日志管理
            String method = Thread.currentThread() .getStackTrace()[1].getMethodName();
            opLogService.addOplog(method+"employeeec");
            return RespBean.ok("添加成功");

        }else {
            return RespBean.error("添加失败");
        }

    }

    @RequestMapping("/delete")
    public RespBean delete(Integer id){
        boolean flag=employeeecService.delete(id);
        if (flag) {
            //获取当前方法并调用日志管理
            String method = Thread.currentThread() .getStackTrace()[1].getMethodName();
            opLogService.addOplog(method+"employeeec");
            return RespBean.ok("删除成功");

        }else {
            return RespBean.error("删除失败");
        }
    }
}
